package com.guofen.controller.yf;


import com.guofen.pojo.RdDischarge;
import com.guofen.service.yf.RdDischargeService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Api("研发出料表")
public class RdDischargeController {
    @Resource
    private RdDischargeService rdDischargeService;

    /*@ApiOperation("提交出料数据现场记录")
    @PostMapping("/research/discharge/add")
    public boolean submitAllInfo(@RequestParam("dischargeDate") String dischargeDate,@RequestParam("dischargeStarttime") String dischargeStarttime,
                                 @RequestParam("dischargeEndtime") String dischargeEndtime,@RequestParam("sieveStarttime") String sieveStarttime,@RequestParam("sieveEndtime") String sieveEndtime,
                                 @RequestParam("insectSeparateStarttime") String insectSeparateStarttime,@RequestParam("insectSeparateEndtime") String insectSeparateEndtime,@RequestParam("deviceName") String deviceName,
                                 @RequestParam("batch") String batch,@RequestParam("zubie") int zubie,@RequestParam("boxNumber") int boxNumber,@RequestParam("dischargeBoxWeight") double dischargeBoxWeight,
                                 @RequestParam("boxWeight") double boxWeight,@RequestParam("insectImpurityWeight") double insectImpurityWeight,@RequestParam("insectDungWeight") double insectDungWeight,
                                 @RequestParam("sieveWeight") double sieveWeight,@RequestParam("surfaceFiberWeight") double surfaceFiberWeight,@RequestParam("insectWeight") double insectWeight,
                                 @RequestParam("impurityWeight") double impurityWeight,@RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return rdDischargeService.submitAllInfo(new RdDischarge(dischargeDate,dischargeStarttime,dischargeEndtime,sieveStarttime,sieveEndtime,insectSeparateStarttime,insectSeparateEndtime,deviceName,batch,zubie,boxNumber,dischargeBoxWeight,
                boxWeight,insectImpurityWeight,insectDungWeight,sieveWeight,surfaceFiberWeight,insectWeight,impurityWeight,recorder,remark));
    }*/
    @ApiOperation("获取 当日 最新 一条记录")
    @GetMapping(value = "/research/dischargeAndSieve/getlast")
    public Result getlast(){
        return  ResultGenerator.genSuccessResult(rdDischargeService.getlast());
    }
    @ApiOperation("提交出料筛分记录")
    @PostMapping(value = "/research/dischargeAndSieve/add")
    public Result addFirst(@RequestParam("dischargeDate") String dischargeDate,@RequestParam("dischargeStarttime") String dischargeStarttime,
                           @RequestParam("dischargeEndtime") String dischargeEndtime,@RequestParam("sieveStarttime") String sieveStarttime,@RequestParam("sieveEndtime") String sieveEndtime,
                           @RequestParam("deviceName1") String deviceName1, @RequestParam("batch") String batch,@RequestParam("zubie") String zubie,@RequestParam("boxNumber") String boxNumber,
                           @RequestParam("dischargeBoxWeight") String dischargeBoxWeight, @RequestParam("boxWeight") String boxWeight,@RequestParam("dischargeWeight") String dischargeWeight,
                           @RequestParam("insectImpurityWeight") String insectImpurityWeight, @RequestParam("insectDungWeight1") String insectDungWeight1,
                           @RequestParam("sieveWeight") String sieveWeight,@RequestParam("surfaceFiberWeight") String surfaceFiberWeight, @RequestParam("recorder") String recorder,@RequestParam(value = "remark",defaultValue = "",required = false) String remark){
        return  ResultGenerator.genSuccessResult(rdDischargeService.addFirst(dischargeDate,batch,zubie,boxNumber,deviceName1,dischargeStarttime,dischargeEndtime,sieveStarttime,sieveEndtime,dischargeBoxWeight,boxWeight,dischargeWeight,insectDungWeight1,sieveWeight,surfaceFiberWeight,insectImpurityWeight,remark,recorder));
    }
    @ApiOperation("获取所有未进行老虫分离的记录")
    @GetMapping(value = "/research/separate/getList")
    public Result getList(){
        return ResultGenerator.genSuccessResult(rdDischargeService.getList());
    }
    @ApiOperation("提交老虫分离记录")
    @PostMapping(value = "/research/separate/add")
    public Result addSecond(@RequestParam("id") String id,@RequestParam("seperateDate") String seperateDate,
                            @RequestParam("insectSeparateStarttime") String insectSeparateStarttime,@RequestParam("insectSeparateEndtime") String insectSeparateEndtime,@RequestParam("device2Name") String device2Name,
                            @RequestParam("insectWeight") String insectWeight, @RequestParam("impurityWeight") String impurityWeight,@RequestParam("insectDungWeight") String insectDungWeight,@RequestParam("remark") String remark,
                            @RequestParam("separatePerson") String separatePerson){
        return ResultGenerator.genSuccessResult(rdDischargeService.addSecond(id,seperateDate,insectSeparateStarttime,insectSeparateEndtime,device2Name,insectWeight,impurityWeight,insectDungWeight,remark,separatePerson));
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/research/discharge/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(rdDischargeService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/research/discharge/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="discharge_date",value="出料日期",required=true) @RequestParam String discharge_date,
                         @ApiParam(name="discharge_starttime",value="出料开始时间",required=true) @RequestParam String discharge_starttime,
                         @ApiParam(name="discharge_endtime",value="出料结束时间",required=true) @RequestParam String discharge_endtime,
                         @ApiParam(name="sieve_starttime",value="筛分开始时间",required=true) @RequestParam String sieve_starttime,
                         @ApiParam(name="sieve_endtime",value="筛分结束时间",required=true) @RequestParam String sieve_endtime,
//                         @ApiParam(name="seperate_date",value="分离日期",required=true) @RequestParam String seperate_date,
                         @ApiParam(name="insect_separate_starttime",value="老虫分离开始时间",required=true) @RequestParam String insect_separate_starttime,
                         @ApiParam(name="insect_separate_endtime",value="老虫分离结束时间",required=true) @RequestParam String insect_separate_endtime,
                         @ApiParam(name="device_name1",value="设备名称1",required=true) @RequestParam String device_name1,
//                         @ApiParam(name="device_name2",value="设备名称2",required=true) @RequestParam String device_name2,
                         @ApiParam(name="batch",value="批次",required=true) @RequestParam String batch,
                         @ApiParam(name="zubie",value="组别",required=true) @RequestParam Integer zubie,
                         @ApiParam(name="box_number",value="盒号",required=true) @RequestParam Integer box_number,
                         @ApiParam(name="discharge_box_weight",value="出料加养殖盒重量",required=true) @RequestParam String discharge_box_weight,
                         @ApiParam(name="box_weight",value="养殖盒重量",required=true) @RequestParam String box_weight,
//                         @ApiParam(name="discharge_weight",value="出料重量",required=true) @RequestParam String discharge_weight,
                         @ApiParam(name="insect_impurity_weight",value="老虫及杂质重量",required=true) @RequestParam String insect_impurity_weight,
                         @ApiParam(name="insect_dung_weight1",value="虫粪重量1",required=true) @RequestParam String insect_dung_weight1,
//                         @ApiParam(name="insect_dung_weight2",value="虫粪重量2",required=true) @RequestParam String insect_dung_weight2,
                         @ApiParam(name="sieve_weight",value="筛上物重量",required=true) @RequestParam String sieve_weight,
                         @ApiParam(name="surface_fiber_weight",value="表层纤维重量",required=true) @RequestParam String surface_fiber_weight,
                         @ApiParam(name="insect_weight",value="老虫重量",required=true) @RequestParam String insect_weight,
                         @ApiParam(name="impurity_weight",value="杂质重量",required=true) @RequestParam String impurity_weight,
                         @ApiParam(name="recorder",value="记录人",required=false) @RequestParam String recorder,
                         @ApiParam(name="separate_person",value="分离人",required=true) @RequestParam String separate_person,
                         @ApiParam(name="remark",value="备注",required=true) @RequestParam String remark) {
        RdDischarge record = new RdDischarge();
//        double dw = Double.parseDouble(discharge_weight);
        double iiw = Double.parseDouble(insect_impurity_weight);
        double idw1 = Double.parseDouble(insect_dung_weight1);
//        double idw2 = Double.parseDouble(insect_dung_weight2);
        double sw = Double.parseDouble(sieve_weight);
        double sfw = Double.parseDouble(surface_fiber_weight);
        double inw = Double.parseDouble(insect_weight);
        double imw = Double.parseDouble(impurity_weight);
        double dbw = Double.parseDouble(discharge_box_weight);
        double bw = Double.parseDouble(box_weight);
        record.setId(id);
        record.setDischargeDate(discharge_date);
        record.setDischargeStarttime(discharge_starttime);
        record.setDischargeEndtime(discharge_endtime);
        record.setSieveStarttime(sieve_starttime);
        record.setSieveEndtime(sieve_endtime);
//        record.setSeperateDate(seperate_date);

        record.setInsectSeparateStarttime(insect_separate_starttime);
        record.setInsectSeparateEndtime(insect_separate_endtime);
        record.setDeviceName1(device_name1);
//        record.setDeviceName2(device_name2);
        record.setBatch(batch);
        record.setZubie(zubie);
        record.setBoxNumber(box_number);
        record.setDischargeBoxWeight(dbw);
        record.setBoxWeight(bw);
//        record.setDischargeWeight(dw);
        record.setInsectImpurityWeight(iiw);
        record.setInsectDungWeight1(idw1);
//        record.setInsectDungWeight2(idw2);
        record.setSieveWeight(sw);
        record.setSurfaceFiberWeight(sfw);
        record.setInsectWeight(inw);
        record.setImpurityWeight(imw);
        record.setRecorder(recorder);
        record.setSeparatePerson(separate_person);
        record.setRemark(remark);

        return ResultGenerator.genSuccessResult(rdDischargeService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/research/discharge/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(rdDischargeService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(rdDischargeService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}